<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>Material of Analysis | 国际化支持(internationalization)</title>
    <meta name="description" content="The analytical data that you often use to learn">
    <link rel="icon" href="/material/logo.png">
  <link rel="manifest" href="/material/manifest.json">
  <meta name="theme-color" content="#3eaf7c">
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-status-bar-style" content="black">
  <link rel="apple-touch-icon" href="/material/icons/apple-touch-icon-152x152.png">
  <link rel="mask-icon" href="/material/icons/safari-pinned-tab.svg" color="#3eaf7c">
  <meta name="msapplication-TileImage" content="/icons/msapplication-icon-144x144.png">
  <meta name="msapplication-TileColor" content="#000000">
    
    <link rel="preload" href="/material/assets/css/0.styles.89749010.css" as="style"><link rel="preload" href="/material/assets/js/app.671f232e.js" as="script"><link rel="preload" href="/material/assets/js/3.2af42d2c.js" as="script"><link rel="prefetch" href="/material/assets/js/9.6ad28882.js"><link rel="prefetch" href="/material/assets/js/1.a893eea4.js"><link rel="prefetch" href="/material/assets/js/2.ad32dd32.js"><link rel="prefetch" href="/material/assets/js/4.b8a50edf.js"><link rel="prefetch" href="/material/assets/js/5.3a34f633.js"><link rel="prefetch" href="/material/assets/js/6.36baf8b1.js"><link rel="prefetch" href="/material/assets/js/7.23741c7b.js"><link rel="prefetch" href="/material/assets/js/8.0b506f6a.js"><link rel="prefetch" href="/material/assets/js/10.aa5bc1f8.js"><link rel="prefetch" href="/material/assets/js/11.b5d01b0b.js"><link rel="prefetch" href="/material/assets/js/12.2aab57fe.js"><link rel="prefetch" href="/material/assets/js/13.17c8fcb3.js"><link rel="prefetch" href="/material/assets/js/14.b0d8de38.js"><link rel="prefetch" href="/material/assets/js/15.95c4b4d8.js"><link rel="prefetch" href="/material/assets/js/16.8279b098.js"><link rel="prefetch" href="/material/assets/js/17.c88c3a9c.js"><link rel="prefetch" href="/material/assets/js/18.0635186f.js"><link rel="prefetch" href="/material/assets/js/19.5e722a99.js">
    <link rel="stylesheet" href="/material/assets/css/0.styles.89749010.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container no-sidebar"><header class="navbar"><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div><a href="/material/" class="home-link router-link-active"><!----><span class="site-name">
      Material of Analysis
    </span></a><div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""><!----></div><nav class="nav-links can-hide"><div class="nav-item"><a href="/material/basic/" class="nav-link">基础</a></div><a href="https://github.com/docschina/vuepress" target="_blank" rel="noopener noreferrer" class="repo-link">
    GitHub
    <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path><polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></nav></div></header><div class="sidebar-mask"></div><div class="sidebar"><nav class="nav-links"><div class="nav-item"><a href="/material/basic/" class="nav-link">基础</a></div><a href="https://github.com/docschina/vuepress" target="_blank" rel="noopener noreferrer" class="repo-link">
    GitHub
    <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path><polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></nav><!----></div><div class="page"><div class="content"><h1 id="国际化支持-internationalization"><a href="#国际化支持-internationalization" aria-hidden="true" class="header-anchor">#</a> 国际化支持(internationalization)</h1><h2 id="网站级别的国际化配置-site-level-i18n-config"><a href="#网站级别的国际化配置-site-level-i18n-config" aria-hidden="true" class="header-anchor">#</a> 网站级别的国际化配置(site level i18n config)</h2><p>想要在 VuePress 中支持多语言，首先你需要使用如下的文件结构：</p><pre class="language-text"><code>/
├─ README.md
├─ foo.md
├─ /nested/
│  └─ README.md
└─ /zh/
   ├─ README.md
   ├─ foo.md
   └─ /zh/nested/
      └─ README.md
</code></pre><p>然后，在 <code>.vuepress/config.js</code> 中指定 <code>locales</code> 选项：</p><pre class="language-js"><code>module<span class="token punctuation">.</span>exports <span class="token operator">=</span> <span class="token punctuation">{</span>
  locales<span class="token punctuation">:</span> <span class="token punctuation">{</span>
    <span class="token comment">// 每个语言对象的键(key)，是语言的访问路径。</span>
    <span class="token comment">// 然而，一种特例是将 '/' 作为默认语言的访问路径。</span>
    <span class="token string">'/'</span><span class="token punctuation">:</span> <span class="token punctuation">{</span>
      lang<span class="token punctuation">:</span> <span class="token string">'en-US'</span><span class="token punctuation">,</span> <span class="token comment">// 这个值会被设置在 &lt;html&gt; 的 lang 属性上</span>
      title<span class="token punctuation">:</span> <span class="token string">'VuePress'</span><span class="token punctuation">,</span>
      description<span class="token punctuation">:</span> <span class="token string">'Vue-powered Static Site Generator'</span>
    <span class="token punctuation">}</span><span class="token punctuation">,</span>
    <span class="token string">'/zh/'</span><span class="token punctuation">:</span> <span class="token punctuation">{</span>
      lang<span class="token punctuation">:</span> <span class="token string">'zh-CN'</span><span class="token punctuation">,</span>
      title<span class="token punctuation">:</span> <span class="token string">'VuePress'</span><span class="token punctuation">,</span>
      description<span class="token punctuation">:</span> <span class="token string">'Vue 驱动的静态网站生成工具'</span>
    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre><p>如果某个语言对象没有声明 <code>title</code> 或 <code>description</code>，VuePress 会尝试获取根语言对象上相应的值。如果每个语言对象都声明了 <code>title</code> 和 <code>description</code>，则可以省略根语言对象上的 <code>title</code> 和 <code>description</code>。</p><h2 id="默认主题的国际化配置-default-theme-i18n-config"><a href="#默认主题的国际化配置-default-theme-i18n-config" aria-hidden="true" class="header-anchor">#</a> 默认主题的国际化配置(default theme i18n config)</h2><p>默认主题也内置国际化支持，可以通过 <code>themeConfig.locales</code> 来配置，与上面配置相同，也使用 <code>{ path: config }</code> 这种（路径+配置对象）格式。除了可以配置一些整个网站都会用到的文本，每个语言对象都有自己的 <a href="/material/default-theme-config/#导航栏">导航栏</a> 和 <a href="/material/default-theme-config/#侧边栏">侧边栏</a>。</p><pre class="language-js"><code>module<span class="token punctuation">.</span>exports <span class="token operator">=</span> <span class="token punctuation">{</span>
  locales<span class="token punctuation">:</span> <span class="token punctuation">{</span> <span class="token comment">/* ... */</span> <span class="token punctuation">}</span><span class="token punctuation">,</span>
  themeConfig<span class="token punctuation">:</span> <span class="token punctuation">{</span>
    locales<span class="token punctuation">:</span> <span class="token punctuation">{</span>
      <span class="token string">'/'</span><span class="token punctuation">:</span> <span class="token punctuation">{</span>
        <span class="token comment">// text for the language dropdown</span>
        selectText<span class="token punctuation">:</span> <span class="token string">'Languages'</span><span class="token punctuation">,</span>
        <span class="token comment">// label for this locale in the language dropdown</span>
        label<span class="token punctuation">:</span> <span class="token string">'English'</span><span class="token punctuation">,</span>
        <span class="token comment">// text for the edit-on-github link</span>
        editLinkText<span class="token punctuation">:</span> <span class="token string">'Edit this page on GitHub'</span><span class="token punctuation">,</span>
        <span class="token comment">// algolia docsearch options for current locale</span>
        algolia<span class="token punctuation">:</span> <span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">,</span>
        nav<span class="token punctuation">:</span> <span class="token punctuation">[</span>
          <span class="token punctuation">{</span> text<span class="token punctuation">:</span> <span class="token string">'Nested'</span><span class="token punctuation">,</span> link<span class="token punctuation">:</span> <span class="token string">'/nested/'</span> <span class="token punctuation">}</span>
        <span class="token punctuation">]</span><span class="token punctuation">,</span>
        sidebar<span class="token punctuation">:</span> <span class="token punctuation">{</span>
          <span class="token string">'/'</span><span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token comment">/* ... */</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
          <span class="token string">'/nested/'</span><span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token comment">/* ... */</span><span class="token punctuation">]</span>
        <span class="token punctuation">}</span>
      <span class="token punctuation">}</span><span class="token punctuation">,</span>
      <span class="token string">'/zh/'</span><span class="token punctuation">:</span> <span class="token punctuation">{</span>
        <span class="token comment">// 语言下拉菜单的展示文本</span>
        selectText<span class="token punctuation">:</span> <span class="token string">'选择语言'</span><span class="token punctuation">,</span>
        <span class="token comment">// 该语言在下拉菜单中的 label 标签</span>
        label<span class="token punctuation">:</span> <span class="token string">'简体中文'</span><span class="token punctuation">,</span>
        <span class="token comment">// github 编辑链接的文字</span>
        editLinkText<span class="token punctuation">:</span> <span class="token string">'在 GitHub 上编辑此页'</span><span class="token punctuation">,</span>
        nav<span class="token punctuation">:</span> <span class="token punctuation">[</span>
          <span class="token punctuation">{</span> text<span class="token punctuation">:</span> <span class="token string">'嵌套'</span><span class="token punctuation">,</span> link<span class="token punctuation">:</span> <span class="token string">'/zh/nested/'</span> <span class="token punctuation">}</span>
        <span class="token punctuation">]</span><span class="token punctuation">,</span>
        algolia<span class="token punctuation">:</span> <span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">,</span>
        sidebar<span class="token punctuation">:</span> <span class="token punctuation">{</span>
          <span class="token string">'/zh/'</span><span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token comment">/* ... */</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
          <span class="token string">'/zh/nested/'</span><span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token comment">/* ... */</span><span class="token punctuation">]</span>
        <span class="token punctuation">}</span>
      <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre></div><div class="content edit-link"><a href="https://github.com/docschina/vuepress/edit/master/docs/guide/i18n.md" target="_blank" rel="noopener noreferrer">在GitHub上编辑此页</a><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path><polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></div><!----></div></div></div>
    <script src="/material/assets/js/3.2af42d2c.js" defer></script><script src="/material/assets/js/app.671f232e.js" defer></script>
  </body>
</html>
